home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TP-TSR.ARJ / CONSOLE.PAS < prev    next >
Pascal/Delphi Source File  |  1989-02-11  |  9KB  |  255 lines

  1. {══════════════════════════════ CONSOLE.PAS ══════════════════════════════}
  2. { ─────────  Turbo 4.0/5.0 stay-resident demonstration program  ───────── }
  3. {                 Copyright (c) 1989  Richard W. Prescott                 }
  4. { This Unit provides routines for changing the cursor shape, as well as   }
  5. { substitutes for ReadKey, WhereX/Y, and WRITE which require less code    }
  6. { and do not respond to Ctrl-C and Ctrl-Break.                            }
  7. {═════════════════════════════════════════════════════════════════════════}
  8. { This Unit was compiled and assembled using Turbo Pascal Version 5.0     }
  9. { and TP&Asm Version 2 ß.  TP&Asm provides an integrated compile-time     }
  10. { assembler within the Turbo development environment (and the command     }
  11. { line compiler TPC), resulting in an ASSEMBLY Development Environment    }
  12. { which is identical to your PASCAL Development Environment.              }
  13. {                                                                         }
  14. { TP&Asm Version 2.0 will be available from me for $49 plus $3 P&H.  The  }
  15. { current Beta Test Version 2 ß is available now for $39 plus $3 P&H,     }
  16. { with a free upgrade to 2.0 when it becomes available.                   }
  17. {          Please see the README file for further information.            }
  18. {═════════════════════════════════════════════════════════════════════════}
  19.  
  20. Unit CONSOLE;
  21.  
  22. INTERFACE
  23. VAR
  24.   MaxColumn: BYTE; {- maximum screen column number as reported by the BIOS -}
  25.  
  26. PROCEDURE WriteSubStr(VAR S; Index,Count: WORD);
  27. PROCEDURE WriteChar(Ch0: CHAR);
  28.  
  29. FUNCTION ReadCursor: WORD;
  30. FUNCTION WhereX: BYTE;
  31. FUNCTION WhereY: BYTE;
  32. PROCEDURE SetCursor(Posn: WORD);
  33.  
  34. PROCEDURE WideCursor; 
  35. PROCEDURE ThinCursor; 
  36. PROCEDURE HideCursor; 
  37.  
  38.  
  39. FUNCTION BiosReadKey: CHAR; {compatible with T4 ReadKey w/o CheckBreak}
  40.  
  41. {══════════════════════════════ BiosFullKey ══════════════════════════════}
  42. { Read keyboard without echo to screen.  (Similar to ReadKey in CRT Unit) }
  43. { Returns a WORD with the character read in the low byte and the Scan     }
  44. { code of the key in the high byte.  Returns all keys, including extended }
  45. { keys, in a single call.  Useful if you want to DIFFERENTIATE "Enter"    }
  46. { from ^M, '+' from "Grey+", etc.  Treats Ctrl-C and Ctrl-Break the same  }
  47. { as all other keys, returning a character and scan code without          }
  48. { executing a user break.                                                 }
  49. {══════════════════════════════ BiosFullKey ══════════════════════════════}
  50. FUNCTION BiosFullKey: WORD; {- Inline Directive -}
  51.   ASSEMBLE
  52.     Xor Ah,Ah
  53.     Int 016
  54.   END; {Assemble}
  55.  
  56.  
  57. {═══════════════════════════════ LookAhead ═══════════════════════════════}
  58. { Same as BiosFullKey but leave keystroke in buffer for subsequent read.  }
  59. {═══════════════════════════════ LookAhead ═══════════════════════════════}
  60. FUNCTION LookAhead:   WORD; {- Inline Directive -}
  61.   ASSEMBLE
  62.   WaitLoop:
  63.     Mov Ah,1
  64.     Int 016
  65.     jZ WaitLoop
  66.   END; {Assemble}
  67.  
  68.  
  69. {══════════════════════════════ DosReadKey ═══════════════════════════════}
  70. { Read keyboard without echo to screen.  (Similar to ReadKey in CRT Unit) }
  71. { Returns the same character that would be returned by ReadKey, except    }
  72. { that ANSI.SYS macros are expanded and Ctrl-C and Ctrl-Break are treated }
  73. { as characters rather than as user break requests.                       }
  74. {══════════════════════════════ DosReadKey ═══════════════════════════════}
  75. FUNCTION DosReadKey:  CHAR; {- Inline Directive -}
  76.   ASSEMBLE
  77.     Mov Ah,7
  78.     Int 21h
  79.   END; {Assemble}
  80.  
  81.  
  82. {═════════════════════════════ DefaultDrive ══════════════════════════════}
  83. { Returns the default drive as a capital letter.                          }
  84. {═════════════════════════════ DefaultDrive ══════════════════════════════}
  85. FUNCTION DefaultDrive: CHAR; {- Inline Directive -}
  86.   ASSEMBLE 
  87.     Mov Ah,$19
  88.     Int $21
  89.     Add Al,$41
  90.   END; {Assemble}
  91.  
  92.  
  93. IMPLEMENTATION
  94. {$S-} 
  95.  
  96.  
  97. {══════════════════════════════ WriteSubStr ══════════════════════════════}
  98. { Write a substring to the screen using DOS, without checking for a user  }
  99. { break.  Uses same parameters as COPY to describe the desired substring. }
  100. {══════════════════════════════ WriteSubStr ══════════════════════════════}
  101. PROCEDURE WriteSubStr(VAR S; Index,Count: WORD);
  102. BEGIN
  103. Assemble
  104.   Mov Cx,Count
  105.   jCXZ Finish
  106.   Push Ds
  107.   Lds Si,S
  108.   Add Si,Index
  109.   Mov Ah,06    ;Direct Console I/O
  110.   Cld          ;set Forward
  111. L0:
  112.   LodSB
  113.   Mov Dl,Al
  114.   Cmp Dl,255      ;function 06 cannot display #255
  115.   IF E Mov Dl,' ' ;Display Space instead
  116.   Int 021
  117.   Loop L0
  118.   Pop Ds
  119. Finish:
  120. END; {Assemble}
  121. END; {PROCEDURE WriteSubStr}
  122.  
  123.  
  124. {═══════════════════════════════ WriteChar ═══════════════════════════════}
  125. { Write a single character to the screen using DOS, without checking for  }
  126. { a user break.                                                           }
  127. {═══════════════════════════════ WriteChar ═══════════════════════════════}
  128. PROCEDURE WriteChar(Ch0: CHAR);
  129. BEGIN
  130. Assemble
  131.   Mov Ah,06  ;Direct Console I/O
  132.   Mov Dl,Ch0
  133.   Cmp Dl,255      ;function 06 cannot display #255
  134.   IF E Mov Dl,' ' ;Display Space instead
  135.   Int 021
  136.   END; {Assemble}
  137. END; {PROCEDURE WriteChar}
  138.  
  139.  
  140. {══════════════════════════════ ReadCursor ═══════════════════════════════}
  141. { Return cursor position as a WORD with Lo byte = X and Hi byte = Y.      }
  142. { Sets MaxColumn to maximum screen column number as reported by the BIOS. }
  143. {══════════════════════════════ ReadCursor ═══════════════════════════════}
  144. FUNCTION ReadCursor: WORD;
  145. BEGIN
  146. ASSEMBLE
  147.   Mov Ah,0Fh
  148.   Int 10h           ;put Active Video Page into Bh
  149.   Mov MaxColumn,Ah
  150.   Mov Ah,03
  151.   Int 10h           ;Get Coords
  152.   Inc Dh,Dl         ;Use (1,1) for UpperLeft
  153.   Mov ReadCursor,Dx ;Put in Function Result by name
  154.   END; {Assemble}
  155. END; {FUNCTION ReadCursor}
  156.  
  157.  
  158. {═════════════════════════════ WhereX/WhereY ═════════════════════════════}
  159. { Provides same function as CRT unit WhereX/WhereY.                       }
  160. {═════════════════════════════ WhereX/WhereY ═════════════════════════════}
  161. FUNCTION WhereX: BYTE;
  162. BEGIN WhereX := Lo(ReadCursor); END; {FUNCTION WhereX}
  163. FUNCTION WhereY: BYTE;
  164. BEGIN WhereY := Hi(ReadCursor); END; {FUNCTION WhereY}
  165.  
  166.  
  167. {═══════════════════════════════ SetCursor ═══════════════════════════════}
  168. { Set cursor position to WORD value which specifies X position in Lo byte }
  169. { and Y position in Hi byte.                                              }
  170. {═══════════════════════════════ SetCursor ═══════════════════════════════}
  171. PROCEDURE SetCursor(Posn: WORD);
  172. BEGIN
  173. ASSEMBLE
  174.   Mov Ah,0Fh
  175.   Int 10h     ;put Active Video Page into Bh
  176.   Mov Dx,Posn
  177.   Dec Dh,Dl   ;BIOS uses (0,0) for UpperLeft
  178.   Mov Ah,02
  179.   Int 10h     ;set Coords
  180.   END; {Assemble}
  181. END; {PROCEDURE SetCursor}
  182.  
  183.  
  184. {══════════════════════════════ WideCursor ═══════════════════════════════}
  185. { Set cursor shape to indicate insert mode.                               }
  186. {══════════════════════════════ WideCursor ═══════════════════════════════}
  187. PROCEDURE WideCursor; BEGIN
  188. ASSEMBLE
  189.   Mov Ah,0Fh
  190.   Int 10h     ;put Active Video Page into Bh, Video mode in Al
  191.   Mov Cx,0507
  192.   Cmp Al,07h
  193.   IF E Mov Cx,080C
  194.   Mov Ah,01
  195.   Int 10h     ;Set CursorType from Cx
  196.   END; {Assemble}
  197. END; {PROCEDURE WideCursor}
  198.  
  199.  
  200. {══════════════════════════════ ThinCursor ═══════════════════════════════}
  201. { Set cursor shape to indicate overwrite mode.                            }
  202. {══════════════════════════════ ThinCursor ═══════════════════════════════}
  203. PROCEDURE ThinCursor; BEGIN
  204. ASSEMBLE
  205.   Mov Ah,0Fh
  206.   Int 10h     ;put Active Video Page into Bh, Video mode in Al
  207.   Mov Cx,0707
  208.   Cmp Al,07h
  209.   IF E Mov Cx,0B0C
  210.   Mov Ah,01
  211.   Int 10h     ;Set CursorType from Cx
  212.   END; {Assemble}
  213. END; {PROCEDURE ThinCursor}
  214.  
  215.  
  216. {══════════════════════════════ HideCursor ═══════════════════════════════}
  217. { Turn off cursor display by setting starting line out of range.  This    }
  218. { technique may not work on all displays.                                 }
  219. {══════════════════════════════ HideCursor ═══════════════════════════════}
  220. PROCEDURE HideCursor; BEGIN
  221. ASSEMBLE
  222.   Mov Ah,0Fh
  223.   Int 10h     ;put Active Video Page into Bh
  224.   Mov Cx,02000 ;set bit 5 of Ch
  225.   Mov Ah,01
  226.   Int 10h     ;Set CursorType from Cx
  227.   END; {Assemble}
  228. END; {PROCEDURE HideCursor}
  229.  
  230.  
  231. {══════════════════════════════ BiosReadKey ══════════════════════════════}
  232. { Read keyboard without echo to screen.  (Similar to ReadKey in CRT Unit) }
  233. { Returns the same character that would be returned by ReadKey, except    }
  234. { that Ctrl-C and Ctrl-Break are treated as characters rather than as     }
  235. { user break requests.  ANSI.SYS macros are not expanded.                 }
  236. {══════════════════════════════ BiosReadKey ══════════════════════════════}
  237. CONST BiosSaveScan: BYTE = 0;
  238. FUNCTION BiosReadKey: CHAR; {compatible with T4 ReadKey w/o CheckBreak}
  239. BEGIN 
  240. ASSEMBLE
  241.   Xor Ax,Ax            ; Clear Ah and Al
  242.   Xchg Al,BiosSaveScan ; Clear SaveScan
  243.   Or Al,Al             ; Check Prior Scan
  244.   jNZ Return           ; NZ, Return it
  245.   Int 016              ; Else Get key via function 0
  246.   Or Al,Al             ; Check Char
  247.   jNZ Return           ; NZ, Return it
  248.   Mov BiosSaveScan,Ah  ; Else Save Scan and return 0
  249. Return:
  250.   Mov BiosReadKey,Al
  251.   END; {Assemble}
  252. END; {FUNCTION BiosReadKey: BYTE; }
  253.  
  254. END.
  255.